<template>
	<view>
		<u-cell-group>
			<u-cell-item icon="edit-pen-fill" title="修改密码" @click="handleToEditPassword"></u-cell-item>
			<u-cell-item icon="warning-fill" title="退出登录" @click="handleToLogout"></u-cell-item>
		</u-cell-group>
		<u-modal v-model="show" :content="content" :show-cancel-button="true" @confirm="handleToConfirmLogout"></u-modal>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	import {
		logout
	} from '../../api/user'
	export default {
		data() {
			return {
				show: false,
				content: '确定要退出吗'
			}
		},
		methods: {
			handleToLogout() {
				if (!this.show) {
					this.show = !this.show;
				}
			},
			handleToConfirmLogout() {
				this.$store.dispatch('logout').then(res => {
					this.show = !this.show;
					this.$refs.uToast.show({
						title: '注销成功',
						type: 'success',
						isTab: true,
						url: '/pages/center/index',
						duration: 500,
						position: 'top'
					})
				})
			},
			handleToEditPassword() {
				uni.navigateTo({
					url: '/pages/center/reset?type=0'
				})
			}
		}
	}
</script>

<style scoped>
	page {
		min-height: 100vh;
		background-color: #ededed;
	}
</style>
